package com.winit.common.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by wangjian on 16/1/17.
 */
public class BaseController {

    static final Logger logger = LoggerFactory.getLogger(BaseController.class);

    public Map getRtn(String code, String desc) {
        return getRtn(code, desc, null);
    }

    public <T> Map getRtn(String code, String desc, T data) {
        Map rtnMap = new HashMap();
        rtnMap.put("code", code);
        rtnMap.put("desc", desc);
        rtnMap.put("data", data);
        return rtnMap;
    }

    @ExceptionHandler
    public Map exp(HttpServletRequest request, Exception ex) {
        logger.error("系统异常", ex);
        return getRtn("4", "系统异常,请联系管理员!" + ex.getMessage(), null);
    }
}
